import 'package:flutter/material.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:flutter_unionad/flutter_unionad.dart';
import 'package:geomancy/styles/index.dart';
import 'package:go_router/go_router.dart';

class SplashPage extends StatefulWidget {
  const SplashPage({super.key});

  @override
  State<SplashPage> createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  bool _offstage = true;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Offstage(
          offstage: _offstage,
          child: FlutterUnionadSplashAdView(
            //android 开屏广告广告id 必填 889033013 102729400
            androidCodeId: "890550085",
            //ios 开屏广告广告id 必填
            iosCodeId: "890550085",
            //是否支持 DeepLink 选填
            supportDeepLink: true,
            // 期望view 宽度 dp 选填
            width: MediaQuery.of(context).size.width,
            //期望view高度 dp 选填
            height: MediaQuery.of(context).size.height,
            //超时时间
            timeout: 3000,
            callBack: FlutterUnionadSplashCallBack(
              onShow: () {
                print("开屏广告显示");
                setState(() => _offstage = false);
                FlutterNativeSplash.remove();
              },
              onClick: () {
                print("开屏广告点击");
              },
              onFail: (error) {
                print("开屏广告失败 $error");
                context.replace('/');
              },
              onFinish: () {
                print("开屏广告倒计时结束");
                context.replace('/');
              },
              onSkip: () {
                print("开屏广告跳过");
                context.replace('/');
              },
              onTimeOut: () {
                print("开屏广告超时");
              },
            ),
          ),
        ),
        Expanded(
          child: Container(
            color: ColorStyle.pageDefaultColor,
          ),
        )
      ],
    );
  }
}
